package com.changli01.string;

import org.junit.Test;
/*
·boolean isEmpty():字符串是否为空
·int length():返回字符串的长度
·String concat(xx):拼接
·boolean equals(Object obj):比较字符串是否相等，区分大小写
·boolean equalslgnoreCase(Object obj):比较字符串是否相等，不区分大小写
·int compareTo(string other):比较字符串大小，区分大小写，按照Unicode编码值比较大小
·int compareTolgnoreCase(string other):比较字符串大小，不区分大小写
·String toLowerCase():将字符串中大写字母转为小写
·String toUppercase():将字符串中小写字母转为大写
·String trim():去掉字符串前后空白符
·public String interm():结果在常量池中共享

* */
public class StringMethodTest1 {
    @Test
//·boolean isEmpty():字符串是否为空
    public void test1() {
        String s1 = "";
        String s2 =new String();
        String s3 =new String("");
        System.out.println(s1.isEmpty());
        System.out.println(s2.isEmpty());
        System.out.println(s3.isEmpty());
    }
    @Test
    public void test2() {
        String s1 = "abc";
        String s2 = "Abc";
        System.out.println(s1.equals(s2)); // false
        System.out.println(s1.equalsIgnoreCase(s2));// true
    }

    @Test
    public void test3() {
        String s1 = "abc";
        String s2 = "Abc";
        //a->97  A->65
        System.out.println(s1.compareTo(s2));//32
        ///忽略大小写
        System.out.println(s1.compareToIgnoreCase(s2)); // 0

    }
    @Test
    public void test4() {
        String s1 = "abc";
        String s2 = "ABC";
        System.out.println(s2.toLowerCase());//"abc"
        System.out.println(s1.toUpperCase()); //"ABC"
    }

    @Test
    public void test5() {
        String s1 = "          abc            ";
        System.out.println(s1);
        System.out.println(s1.trim()); // "abc"
    }
    @Test
    public void test6() {
        String s1 = "abc";
        String s2 = new String ("abc");
        s2.intern();
        System.out.println(s1 == s2);
    }
    @Test
    public void test7() {
        String s1 = "abc";
        System.out.println(s1.contains("b"));// true

        System.out.println(s1.indexOf("c"));  // 2
        System.out.println(s1.indexOf("c", 3));  // -1
        System.out.println(s1.lastIndexOf("c"));//从后往前找
    }
    @Test
    public void test8() {
        String s1 = "abc";
        String s2 = "abc33434abc";
        System.out.println(s2.lastIndexOf("abc", s2.length() - 1));


    }
    @Test
    public void test9() {
        String s1 = "lyf and zky";
        System.out.println(s1.substring(s1.indexOf("z"), s1.length()));
    }

    @Test
    public void test10() {
        String s1 = "csust";
        System.out.println(s1.startsWith("c")); //true
        System.out.println(s1.startsWith("c", 2)); // false
        System.out.println(s1.endsWith("c")); //false
        System.out.println(s1.endsWith("t")); //true
    }
    @Test
    public void test11() {
        String s1 = "hello";
        System.out.println(s1.replace("l", "w"));
        System.out.println(s1.replace("ll", "wwwwww"));
        System.out.println(s1.replaceAll("l", "w"));
    }
}
